<div class="goods-dialog" id="gift-dialog">
    <ul class="nav nav-tabs v-nav-tabs pt-15" role="tablist">
        <li role="presentation" class="active"><a href="#list" aria-controls="list" role="tab" data-toggle="tab" class="flex-auto-center">赠品列表</a></li>
        <div class="input-group search-input-group pull-right">
            <input id="search_text" type="text" class="form-control" name="name" placeholder="赠品名称">
            <span class="input-group-btn"><button class="btn search search-color" >搜索</button></span>
        </div>
    </ul>
    <div class="dialog-box tab-content">
        <div role="tabpanel" class="tab-pane fade in active" id="list">
            <table class="table v-table table-auto-center">
                <thead>
                    <tr>
                        <th>赠品信息</th>
                        <th>已赠/剩余库存</th>
                        <th width="150">操作</th>
                    </tr>
                </thead>
                <tbody id="content"></tbody>
            </table>
            <nav aria-label="Page navigation" class="clearfix">
                <ul id="page_gift" class="pagination pull-right"></ul>
            </nav>
        </div>
    </div>
    <input type="hidden" id="selectedData">
</div>
<script id='gift_content' type='text/html'>
    <%each data as item itemid%>
    <tr>
        <td>
            <div class="media text-left">
                <div class="media-left">
                    <img src="<%item.pic_cover_mid%>" onerror="this.src='http://iph.href.lu/60x60';" width="60" height="60">
                </div>
                <div class="media-body max-w-300">
                    <div class="line-2-ellipsis"><%item.gift_name%></div>
                    <div class="line-1-ellipsis text-danger strong"><%item.price%></div>
                </div>
            </div>
        </td>
		<td><%item.sended%>/<%item.stock%></td>
        <td>
            <a href="javascript:;" class="text-primary selec_btn" data-img="<%item.pic_cover_mid%>" data-gift_name="<%item.gift_name%>" data-price="<%item.price%>" data-promotion_gift_id="<%item.promotion_gift_id%>">选择</a>
        </td>
    </tr>
    <%/each%>
</script>
<script>
require(['util','tpl'],function(util,tpl){
    var all_data = {};
    util.initPage(LoadingInfo,'page_gift')
    function LoadingInfo(page_index){
        var val = $("#search_text").val();
        $.ajax({
            type: "post",
            url: "{$prizeTypeUrl}",
            async: true,
            data: {
                "page_index": page_index,
                "search_text": val,
                "type":6
            },
            success: function (data) {
                all_data = data;
                html ='';
                html += '<tr><th colspan="3">请添加赠品</th></tr>';
                if(tpl('gift_content', all_data)){
	                $('#gift-dialog #content').html(tpl('gift_content',all_data));
	                $('#page_gift').paginator('option', {
	                    totalCounts: data.total_count
	                });
                }else{
                    $('#gift-dialog #content').html(html);
                }
            }
        });
    }
    // 搜索
    $('.search').on('click',function(){
        LoadingInfo(1);
    });
    // 选择
    $('#gift-dialog').on('click','.selec_btn',function(){
    	var promotion_gift_id = $(this).data('promotion_gift_id');
    	var gift_name = $(this).data('gift_name');
        var price = $(this).data('price');
        var img = $(this).data('img');
        $('#gift_info .gift-img img').attr('src',img);
        $('#gift_info .gift-name').html(gift_name);
        $('#gift_info .gift-price').html(price);
        $('#gift_info').removeClass('hidden').addClass('show');
        typeId(promotion_gift_id);
        $('.jconfirm-closeIcon').click();
    })
})
</script>